package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.VendorBean;
import com.project.service.IVendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 供应商controller
 */
@RequestMapping("vendor")
@RestController
public class VendorController {

    @Autowired
    private IVendorService vendorService;

    //动态条件分页查询供应商信息
    @RequestMapping("findByItem")
    public IPage<VendorBean> findByItem(Integer pageNO, String name, String ranges){
        return vendorService.findByItem(pageNO, name, ranges);
    }

    //按照id查询供应商信息
    @RequestMapping("findById")
    public VendorBean findById(Integer vendorId){
        return vendorService.findById(vendorId);
    }

    //按照供应商id修改供应商名字和电话
    @RequestMapping("updateVendor")
    public String updateVendor(Integer vendorId, String headerName, String headerPhone){
        vendorService.updateVendor(vendorId,headerName,headerPhone);
        return "ok";
    }

    //根据供应商的名字查询供应商
    @RequestMapping("findByName")
    public VendorBean findByName(String name){
        return vendorService.findByName(name);
    }

    //添加供应商
    @RequestMapping("addVendor")
    public String addVendor(VendorBean vendor){
        vendorService.addVendor(vendor);
        return "ok";
    }

    //查询所有供应商
    @RequestMapping("findAll")
    public List<VendorBean> findAll(){
        return vendorService.findAll();
    }

}
